package com.example.demo.mapper;

import com.example.demo.entity.Student;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface StudentMapper {
    
    // 查询所有学生
    @Select("SELECT * FROM student")
    List<Student> findAll();
    
    // 根据ID查询学生
    @Select("SELECT * FROM student WHERE id = #{id}")
    Student findById(Long id);
    
    // 插入学生信息
    @Insert("INSERT INTO student(name, age, gender, grade, major, phone, email, avatar_url) " +
            "VALUES(#{name}, #{age}, #{gender}, #{grade}, #{major}, #{phone}, #{email}, #{avatarUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Student student);
    
    // 更新学生信息
    @Update("UPDATE student SET name=#{name}, age=#{age}, gender=#{gender}, grade=#{grade}, " +
            "major=#{major}, phone=#{phone}, email=#{email}, avatar_url=#{avatarUrl} WHERE id=#{id}")
    int update(Student student);
    
    // 根据ID删除学生
    @Delete("DELETE FROM student WHERE id = #{id}")
    int deleteById(Long id);
    
    // 根据姓名模糊查询
    @Select("SELECT * FROM student WHERE name LIKE CONCAT('%',#{name},'%')")
    List<Student> findByName(String name);
}